function calculateOligo(sequence) {
    return new Oligo(sequence);
    //return calculatedOligo;
    /*
    form.oligoBox.value = newOligo.Sequence
    form.tmBox.value = newOligo.Tm()
    form.gcBox.value = newOligo.GC()
    form.mwBox.value = newOligo.MW()
    form.odBox.value = newOligo.OD()
    form.lBox.value = newOligo.Sequence.length
    */
}

function Oligo(theString)
{
    this.sequence = RemoveNonBase(theString);
    this.aCount = CountChar(theString, "A");
    this.cCount = CountChar(theString, "C");
    this.gCount = CountChar(theString, "G");
    this.tCount = CountChar(theString, "T");
    this.MT = MT(this.sequence, this.gCount, this.cCount, this.aCount, this.tCount);
    this.GC = GC(this.sequence, this.gCount, this.cCount);
    this.MW = MW(this.sequence, this.gCount, this.cCount, this.aCount, this.tCount);
    this.OD = OD(this.sequence, this.gCount, this.cCount, this.aCount, this.tCount );
}

function OD(seq, gCount, cCount, aCount, tCount)
{
    if (seq.length > 0) {
        return Math.round(1000000 / (gCount * 11.7 + cCount * 7.3 + aCount * 15.4 + tCount * 8.8));
    }
    return "";

}

function MW(seq,gCount, cCount, aCount, tCount)
{
    if (seq.length > 0) {
        return Math.round(313.2 * aCount + 328.2 * gCount + 289.2 * cCount + 304.2 * tCount - 60.96);
    }
    return "";
}

function GC(seq, gCount, cCount)
{
    if (seq.length > 0) {
        return Math.round(100 * ( gCount + cCount ) / seq.length);
    }
    return "";

}

function MT(seq, gCount, cCount, aCount, tCount)
{
    if (seq.length > 0) {
        if (seq.length < 14) {
            return  Math.round(2 * (aCount + tCount) + 4 * (gCount + cCount));
        }
        else {
            return Math.round(64.9 + 41 * ((gCount + cCount - 16.4) / seq.length));
        }
    }
    return "";
}

function RemoveNonBase(theString) {
    var returnString = "";
    for (var i = 0; i < theString.length; i++) {
        if ((theString.toUpperCase().charAt(i) == "A") || (theString.charAt(i) == "G") || (theString.charAt(i) == "C") || (theString.charAt(i) == "T")) {
            returnString += theString.charAt(i);
        }
    }
    return returnString;
}

function CountChar(theString, theChar) {
    var returnValue = 0;
    for (var i = 0; i < theString.length; i++) {
        if (theString.toUpperCase().charAt(i) == theChar) {
            returnValue ++;
        }
    }
    return returnValue;
}

function Disallow(form) {
    form.oligoBox.focus()
}

